package com.atguigu.juc.completableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

/**
 * @author yfstart
 * @create 2022-06-20 11:33
 */
public class CompletableFutureAPIDemo {
  public static void main(String[] args) {
      CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {
          try {
              TimeUnit.MILLISECONDS.sleep(2000);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
          return "hello supplyAsync";
      });

      /// 去掉注释上面计算没有完成，返回 valueIfAbsent
      /// 开启注释上满计算完成，返回计算结果
      try {
        TimeUnit.MILLISECONDS.sleep(3000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    System.out.println(completableFuture.getNow("valueIfAbsent"));
  }
}
